<?php
class setting extends admin{
   public function __construct(){
      parent::__construct();
   }

   public function index(){
      $school_id=(int)$_SESSION['client']['jx_id'];
      $where= ' where school_id='.$school_id;

      $list=db()->getRow('select * from x_bank_config '.$where);
      if(!$list) $list=array();
      $this->ajaxReturn(array('status'=>1,'data'=>$list));
   }

   public function update(){
      if(empty($_POST['id'])) $this->ajaxReturn(array('status'=>0,'info'=>'缺少参数'));
      $id = $_POST['id'];
      $data['real_name'] = $_POST['real_name'];
      $data['bank'] = $_POST['bank'];
      $data['branch'] = $_POST['branch'];
      $data['card_num'] = $_POST['card_num'];
      $data['mobile'] = $_POST['mobile'];
      $affert_num = db()->update('x_bank_config', $data, 'id='.$id);
      if ($affert_num!==false) {
         if ($affert_num>0)  insertlogs('update','修改支付账户(ID:'.$id.')',$data,'id='.$id);
         $this->ajaxReturn(array( 'status' => '1', 'info' => '操作成功' ));
      }
      else $this->ajaxReturn(array( 'status' => '0', 'info' => '操作失败' ));
   }

   public function add(){
      if(!isset($_POST['real_name'])||empty($_POST['real_name'])) $this->ajaxReturn(array('status'=>'0','info'=>'请填写开户名'));
      if(!isset($_POST['bank'])||empty($_POST['bank'])) $this->ajaxReturn(array('status'=>'0','info'=>'请填写开户行'));
      if(!isset($_POST['branch'])||empty($_POST['branch'])) $this->ajaxReturn(array('status'=>'0','info'=>'请填写开户支行'));
      if(!isset($_POST['card_num'])||empty($_POST['card_num'])) $this->ajaxReturn(array('status'=>'0','info'=>'请填写银行卡号'));
      if(!isset($_POST['mobile'])||empty($_POST['mobile'])) $this->ajaxReturn(array('status'=>'0','info'=>'请填写手机号'));
      $data['school_id'] = (int)$_SESSION['client']['jx_id'];
      $data['real_name'] = $_POST['real_name'];
      $data['bank'] = $_POST['bank'];
      $data['branch'] = $_POST['branch'];
      $data['card_num'] = $_POST['card_num'];
      $data['mobile'] = $_POST['mobile'];

      $insert_id = db()->insert('x_bank_config',$data);
      if($insert_id) {
         insertlogs('create','添加支付账户(ID:'.$insert_id.')',$data,$insert_id);
         $this->ajaxReturn(array('status'=>'1','info'=>'操作成功'));
      }
      else $this->ajaxReturn(array('status'=>'0','info'=>'添加失败'));

   }

}
